/**
 * Created by hcadmin on 16/3/14.
 */

define([
    "jquery",
    "IO",
    "UPLOADUI",
    "UPLOAD",
    "jqueryUI",
    "bootbox",
], function($, IO, upui, up, jui, bootbox, definebt) {
    var status = $("#status").attr("value");
    if(status==3 ){
        document.getElementById("text_div").style.display="none";

    }else if(status==1){
        document.getElementById("text_div").innerHTML = "已通过";
        document.getElementById("btn_div").style.display="none";
    }else if(status==2){
        document.getElementById("text_div").innerHTML = "拒绝";
        document.getElementById("btn_div").style.display="none";
    }
    else if(status==4){
        document.getElementById("text_div").style.display="none";
        document.getElementById("btn_div").style.display="none";
    }
    //通过申请
    $(document).on("click","#agree",function(){
        var id = $("#id").attr("value");

        var imgurl = document.getElementById('upimgs').src;


        if(imgurl == undefined || imgurl.length < 10 || imgurl == window.location.href)
        {
            alert("请先上传证书图片");

            return;
        }
        console.log("id++++"+id);
        if(id) {
            bootbox.confirm("确定要通过该认证？", function (result) {
                if (result) {
                    IO.get("act/agree", {id: id,imgurl:imgurl}, function (d) {
                        bootbox.alert(d.msg, function () {
                            if (d.code == 0) {
                                location.href = '/pte/renzheng';
                            }
                        })
                    });
                }
            });
        }
    });

    //拒绝申请
    $(document).on("click","#disagree",function(){
        var id = $("#id").attr("value");
        bootbox.confirm("确定要拒绝该认证？",function(result){
            if(result) {
                IO.get("act/disagree",{id:id},function(d){
                    bootbox.alert(d.msg,function(){
                        if (d.code == 0) {
                            location.href = '/pte/renzheng';
                        }
                    })
                });
            }
        });
    });


    $('#fileupload').fileupload({
        url: '/upload',
        dataType: 'json',
        autoUpload: true,
        acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
        maxFileSize: 10000000, // 10 MB
        disableImageResize: /Android(?!.*Chrome)|Opera/
            .test(window.navigator.userAgent),
        previewMaxWidth: 150,
        previewMaxHeight: 150,
        previewCrop: true
    }).on('fileuploadadd', function (e, data) {
        document.getElementById('upimgs').src = '/images/loading.gif';

    }).on('fileuploadprocessalways', function (e, data) {
        //console.log("fileuploadprocessalways",data);
    }).on('fileuploadprogressall', function (e, data) {
        //console.log("fileuploadprogressall",data);
    }).on('fileuploaddone', function (e, data) {
        //alert('Img'+youpaiImg);
        //alert(data._response.result.url);
        //document.getElementById('upimgs').src = data._response.result.url;
        //console.log(youpaiImg);
        //  console.log("fileuploaddone",data);
        var alt = $(e.target).attr('alt');
        if (!alt)
            alt = '';
        console.log("#upimgs" + alt);
        $("#upimgs" + alt).attr("src", data._response.result.url);
    });

});